﻿using System;
using System.IO;
using System.Windows.Forms;

namespace Remove_File_History_decorations
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var Suchende = "UTC)";
            var Suchstart = " (";
            var Dialog = new FolderBrowserDialog();
            Dialog.ShowNewFolderButton = false;
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                foreach (var DecoratedFile in Directory.GetFiles(Dialog.SelectedPath, @"*.*", SearchOption.AllDirectories))
                    if (!Directory.Exists(DecoratedFile) && DecoratedFile.Contains(Suchende) && DecoratedFile.Contains(Suchstart))
                    {
                        var Endindex = DecoratedFile.LastIndexOf(Suchende);
                        var Startindex = DecoratedFile.LastIndexOf(Suchstart);
                        var PlainFile = DecoratedFile.Substring(0, Startindex) + DecoratedFile.Substring(Endindex + Suchende.Length, DecoratedFile.Length - Endindex - Suchende.Length);
                        File.Move(DecoratedFile, PlainFile);
                    }
                MessageBox.Show("Done removing File History decorations in " + Dialog.SelectedPath);
            }
        }
    }
}